package com.example.demo.mapper;

import com.example.demo.pojo.*;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface AdminMapper {
    @Select("select * from admin where username=#{username} and password=#{password}")
    Admin authenticate(String username, String password);

    @Select("select * from department")
    List<Department> getAllDepartment();

    @Insert("insert into department(name,description,parent_id,status) " +
            "values(#{name},#{description},#{parentId},#{status})")
    void addDepartment(Department department);

    @Update("update department set name=#{name},description=#{description},parent_id=#{parentId}," +
            "update_time=#{updateTime},status=#{status} where id=#{id}")
    void updateDepartment(Department department);

    @Select("select * from doctor")
    List<Doctor> getAllDctor();

    @Insert("insert into doctor(department_id,name,title,description,avatar,working_days,morning_start,morning_end,afternoon_start,afternoon_end,status)" +
            " values(#{departmentId},#{name},#{title},#{description},#{avatar},#{workingDays},#{morningStart},#{morningEnd},#{afternoonStart},#{afternoonEnd},#{status})")
    void addDoctor(Doctor doctor);

    @Update("update doctor set department_id= #{departmentId},name= #{name},title= #{title},description= #{description},avatar= #{avatar},working_days= #{workingDays}," +
            "morning_start= #{morningStart},morning_end= #{morningEnd},afternoon_start= #{afternoonStart},afternoon_end= #{afternoonEnd},status= #{status} where id= #{id}")
    void updateDoctor(Doctor doctor);

    @Delete("delete from doctor where id= #{id}")
    void deleteDoctor(Long id);

    List<ScheduleInfo> getAllScheduleInfoOfDoctor();

    @Update("update schedule set date=#{scheduleDate},period=#{period},total_number=#{totalNumber},available_number=#{availableNumber},price=#{price},status=#{status} where id=#{id}")
    void updateSchdule(ScheduleInfo scheduleInfo);

    @Insert("insert into schedule(doctor_id,date,period,total_number,available_number,price,status)" +
            "values (#{doctorId},#{date},#{period},#{totalNumber},#{availableNumber},#{price},#{status})")
    void addSchedule(Schedule schedule);

    @Delete("delete from schedule where id= #{id}")
    void deleteSchedule(Long id);

    @Select("select * from schedule where id= #{id}")
    Schedule getScheduleById(Long id);

    List<ScheduleInfo> searchScheduleInfo(ScheduleInfo scheduleInfo);

    List<WaitingDetail> getAllWaitingList();

    void updateWaiting(Waiting waiting);

    @Update("update waiting set status=5 where id=#{id}")
    void cancelWaiting(Long id);

    @Update("update waiting set call_time= #{callTime},status=2 where id= #{id}")
    void setCallTime(Date callTime, Long id);

    @Update("update waiting set status=3 where id= #{id}")
    void consultWaiting(Long id);

    @Update("update waiting set status=4 where id= #{id}")
    void finishWaiting(Long id);
}
